package org.zjx;

import lombok.SneakyThrows;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.ServiceConfig;
import org.zjx.common.service.DecisionService;
import org.zjx.service.DecisionServiceImpl;

public class Main {
    @SneakyThrows
    public static void main(String[] args) {
        // 1. 应用配置
        ApplicationConfig applicationConfig = new ApplicationConfig("sample-provider");
        applicationConfig.setCheckSerializable(true);
        applicationConfig.setSerializeCheckStatus("DISABLE");

        // 2. 协议配置（关键修改点）
        ProtocolConfig protocolConfig = new ProtocolConfig();
        protocolConfig.setName("dubbo");
        protocolConfig.setPort(3243);
        protocolConfig.setSerialization("fastjson2"); // 强制使用FastJSON序列化

        // 3. 注册中心配置
        RegistryConfig registryConfig = new RegistryConfig(RegistryConfig.NO_AVAILABLE);

        // 4. 服务配置
        ServiceConfig<DecisionService> serviceConfig = new ServiceConfig<>();
        serviceConfig.setInterface(DecisionService.class);
        serviceConfig.setRef(new DecisionServiceImpl());
        serviceConfig.setRegistry(registryConfig);
        serviceConfig.setProtocol(protocolConfig); // 应用协议配置
        serviceConfig.setApplication(applicationConfig);

        // 5. 全局关闭严格检查（可选，开发环境建议关闭）
        System.setProperty("dubbo.application.serialization-security-check", "false");

        // 6. 暴露服务
        serviceConfig.export();
        System.out.println("DecisionService已暴露，使用序列化协议: " + protocolConfig.getSerialization());

        // 保持进程运行
        System.in.read();
    }
}